<?php

use Faker\Factory as Faker;
use App\Models\WechatUser;
use App\Repositories\WechatUserRepository;

trait MakeWechatUserTrait
{
    /**
     * Create fake instance of WechatUser and save it in database
     *
     * @param array $wechatUserFields
     * @return WechatUser
     */
    public function makeWechatUser($wechatUserFields = [])
    {
        /** @var WechatUserRepository $wechatUserRepo */
        $wechatUserRepo = App::make(WechatUserRepository::class);
        $theme = $this->fakeWechatUserData($wechatUserFields);
        return $wechatUserRepo->create($theme);
    }

    /**
     * Get fake instance of WechatUser
     *
     * @param array $wechatUserFields
     * @return WechatUser
     */
    public function fakeWechatUser($wechatUserFields = [])
    {
        return new WechatUser($this->fakeWechatUserData($wechatUserFields));
    }

    /**
     * Get fake data of WechatUser
     *
     * @param array $postFields
     * @return array
     */
    public function fakeWechatUserData($wechatUserFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'nickname' => $fake->word,
            'openid' => $fake->word,
            'unionid' => $fake->word,
            'sex' => $fake->word,
            'language' => $fake->word,
            'city' => $fake->word,
            'province' => $fake->word,
            'country' => $fake->word,
            'headimgurl' => $fake->word,
            'subscribe' => $fake->word,
            'subscribe_time' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $wechatUserFields);
    }
}
